home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / cipher1a / cypher1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-20  |  12.7 KB  |  431 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Made by Chris Hultberg  9-20-99"
  5.    ClientHeight    =   3225
  6.    ClientLeft      =   1680
  7.    ClientTop       =   3225
  8.    ClientWidth     =   9015
  9.    Icon            =   "CYPHER1.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    PaletteMode     =   1  'UseZOrder
  14.    ScaleHeight     =   3225
  15.    ScaleWidth      =   9015
  16.    ShowInTaskbar   =   0   'False
  17.    Begin VB.CommandButton Command2 
  18.       Caption         =   "Paste"
  19.       Height          =   255
  20.       Left            =   4680
  21.       TabIndex        =   10
  22.       Top             =   2520
  23.       Width           =   855
  24.    End
  25.    Begin VB.CommandButton Command1 
  26.       Caption         =   "Copy"
  27.       Height          =   255
  28.       Left            =   3480
  29.       TabIndex        =   9
  30.       Top             =   2520
  31.       Width           =   975
  32.    End
  33.    Begin VB.CommandButton cmdDecipher 
  34.       Caption         =   "<<"
  35.       Enabled         =   0   'False
  36.       Height          =   495
  37.       Left            =   3960
  38.       TabIndex        =   7
  39.       Top             =   1800
  40.       Width           =   1095
  41.    End
  42.    Begin VB.CommandButton cmdCipher 
  43.       Caption         =   ">>"
  44.       Enabled         =   0   'False
  45.       Height          =   495
  46.       Left            =   3960
  47.       TabIndex        =   6
  48.       Top             =   1080
  49.       Width           =   1095
  50.    End
  51.    Begin VB.TextBox txtPassword 
  52.       Height          =   285
  53.       IMEMode         =   3  'DISABLE
  54.       Left            =   3600
  55.       PasswordChar    =   "*"
  56.       TabIndex        =   5
  57.       Top             =   480
  58.       Width           =   1815
  59.    End
  60.    Begin VB.TextBox txtCipher 
  61.       Height          =   2295
  62.       Left            =   5520
  63.       MultiLine       =   -1  'True
  64.       TabIndex        =   2
  65.       Top             =   120
  66.       Width           =   3375
  67.    End
  68.    Begin VB.TextBox txtPlain 
  69.       Height          =   2295
  70.       Left            =   120
  71.       MultiLine       =   -1  'True
  72.       TabIndex        =   0
  73.       Top             =   120
  74.       Width           =   3375
  75.    End
  76.    Begin VB.Label Label1 
  77.       Alignment       =   2  'Center
  78.       Caption         =   "Copyright (C) Chris Hultberg"
  79.       Height          =   255
  80.       Index           =   5
  81.       Left            =   2880
  82.       TabIndex        =   8
  83.       Top             =   2880
  84.       Width           =   3255
  85.    End
  86.    Begin VB.Label Label1 
  87.       Alignment       =   2  'Center
  88.       Caption         =   "Password"
  89.       Height          =   255
  90.       Index           =   2
  91.       Left            =   3600
  92.       TabIndex        =   4
  93.       Top             =   240
  94.       Width           =   1815
  95.    End
  96.    Begin VB.Label Label1 
  97.       Alignment       =   2  'Center
  98.       Caption         =   "Cipheredtext"
  99.       Height          =   255
  100.       Index           =   1
  101.       Left            =   5400
  102.       TabIndex        =   3
  103.       Top             =   2640
  104.       Width           =   3375
  105.    End
  106.    Begin VB.Label Label1 
  107.       Alignment       =   2  'Center
  108.       Caption         =   "Plaintext"
  109.       Height          =   255
  110.       Index           =   0
  111.       Left            =   0
  112.       TabIndex        =   1
  113.       Top             =   2640
  114.       Width           =   3375
  115.    End
  116.    Begin VB.Menu mnuFile 
  117.       Caption         =   "&File"
  118.       Begin VB.Menu mnuFileCope 
  119.          Caption         =   "&Copy"
  120.       End
  121.       Begin VB.Menu mnuFilePaste 
  122.          Caption         =   "&Paste"
  123.       End
  124.       Begin VB.Menu sep 
  125.          Caption         =   "-"
  126.       End
  127.       Begin VB.Menu mnuFileExit 
  128.          Caption         =   "E&xit"
  129.       End
  130.    End
  131.    Begin VB.Menu mnuEdit 
  132.       Caption         =   "&Edit"
  133.       Begin VB.Menu mnuEditTime 
  134.          Caption         =   "Time/&Date"
  135.       End
  136.    End
  137.    Begin VB.Menu mnuHelp 
  138.       Caption         =   "&Help"
  139.       Begin VB.Menu mnuHelpAbout 
  140.          Caption         =   "&About"
  141.       End
  142.    End
  143. Attribute VB_Name = "Form1"
  144. Attribute VB_GlobalNameSpace = False
  145. Attribute VB_Creatable = False
  146. Attribute VB_PredeclaredId = True
  147. Attribute VB_Exposed = False
  148. Option Explicit
  149. ' Encipher the text using the pasword.
  150. Private Sub Cipher(ByVal password As String, ByVal from_text As String, to_text As String)
  151. Const MIN_ASC = 32  ' Space.
  152. Const MAX_ASC = 126 ' ~.
  153. Const NUM_ASC = MAX_ASC - MIN_ASC + 1
  154. Dim offset As Long
  155. Dim str_len As Integer
  156. Dim i As Integer
  157. Dim ch As Integer
  158.     ' Initialize the random number generator.
  159.     offset = NumericPassword(password)
  160.     Rnd -1
  161.     Randomize offset
  162.     ' Encipher the string.
  163.     str_len = Len(from_text)
  164.     For i = 1 To str_len
  165.         ch = Asc(Mid$(from_text, i, 1))
  166.         If ch >= MIN_ASC And ch <= MAX_ASC Then
  167.             ch = ch - MIN_ASC
  168.             offset = Int((NUM_ASC + 1) * Rnd)
  169.             ch = ((ch + offset) Mod NUM_ASC)
  170.             ch = ch + MIN_ASC
  171.             to_text = to_text & Chr$(ch)
  172.         End If
  173.     Next i
  174. End Sub
  175. ' Encipher the text using the pasword.
  176. Private Sub Decipher(ByVal password As String, ByVal from_text As String, to_text As String)
  177. Const MIN_ASC = 32  ' Space.
  178. Const MAX_ASC = 126 ' ~.
  179. Const NUM_ASC = MAX_ASC - MIN_ASC + 1
  180. Dim offset As Long
  181. Dim str_len As Integer
  182. Dim i As Integer
  183. Dim ch As Integer
  184.     ' Initialize the random number generator.
  185.     offset = NumericPassword(password)
  186.     Rnd -1
  187.     Randomize offset
  188.     ' Encipher the string.
  189.     str_len = Len(from_text)
  190.     For i = 1 To str_len
  191.         ch = Asc(Mid$(from_text, i, 1))
  192.         If ch >= MIN_ASC And ch <= MAX_ASC Then
  193.             ch = ch - MIN_ASC
  194.             offset = Int((NUM_ASC + 1) * Rnd)
  195.             ch = ((ch - offset) Mod NUM_ASC)
  196.             If ch < 0 Then ch = ch + NUM_ASC
  197.             ch = ch + MIN_ASC
  198.             to_text = to_text & Chr$(ch)
  199.         End If
  200.     Next i
  201. End Sub
  202. ' Translate a password into an offset value.
  203. Private Function NumericPassword(ByVal password As String) As Long
  204. Dim value As Long
  205. Dim ch As Long
  206. Dim shift1 As Long
  207. Dim shift2 As Long
  208. Dim i As Integer
  209. Dim str_len As Integer
  210.     str_len = Len(password)
  211.     For i = 1 To str_len
  212.         ' Add the next letter.
  213.         ch = Asc(Mid$(password, i, 1))
  214.         value = value Xor (ch * 2 ^ shift1)
  215.         value = value Xor (ch * 2 ^ shift2)
  216.         ' Change the shift offsets.
  217.         shift1 = (shift1 + 7) Mod 19
  218.         shift2 = (shift2 + 13) Mod 23
  219.     Next i
  220.     NumericPassword = value
  221. End Function
  222. Private Sub cmdCipher_Click()
  223. Dim cipher_text As String
  224.     Cipher txtPassword.Text, txtPlain.Text, cipher_text
  225.     txtCipher.Text = cipher_text
  226. End Sub
  227. Private Sub cmdDecipher_Click()
  228. Dim plain_text As String
  229.     Decipher txtPassword.Text, txtCipher.Text, plain_text
  230.     txtPlain.Text = plain_text
  231. End Sub
  232. Private Sub Command1_Click()
  233.     ' Copy the selected text onto the Clipboard.
  234.     Clipboard.SetText txtCipher
  235. End Sub
  236. Private Sub Command2_Click()
  237.     Form1.txtCipher = Clipboard.GetText()
  238. End Sub
  239. Private Sub Label1_Click(Index As Integer)
  240.     txtPlain.Text = "2002 Kix Ass!"
  241. End Sub
  242. Private Sub mnuEditTime_Click()
  243.     txtCipher.Text = Now
  244.     txtPlain.SelText = Now
  245. End Sub
  246. Private Sub mnuHelpAbout_Click()
  247.     About.Show 1
  248. End Sub
  249. Private Sub mnuFileCope_Click()
  250.     Clipboard.SetText txtCipher
  251. End Sub
  252. Private Sub mnuFileExit_Click()
  253.     End
  254. End Sub
  255. Private Sub mnuFilePaste_Click()
  256.     Form1.txtCipher = Clipboard.GetText()
  257. End Sub
  258. Private Sub txtCipher_Change()
  259.    If txtCipher.Text = "A" Then
  260.    txtCipher.Text = "Dont type anything here."
  261.    End If
  262.    If txtCipher.Text = "a" Then
  263.    txtCipher.Text = "Dont type anything here."
  264.    End If
  265.    If txtCipher.Text = "B" Then
  266.    txtCipher.Text = "Dont type anything here."
  267.    End If
  268.    If txtCipher.Text = "b" Then
  269.    txtCipher.Text = "Dont type anything here."
  270.    End If
  271.    If txtCipher.Text = "C" Then
  272.    txtCipher.Text = "Dont type anything here."
  273.    End If
  274.    If txtCipher.Text = "c" Then
  275.    txtCipher.Text = "Dont type anything here."
  276.    End If
  277.    If txtCipher.Text = "D" Then
  278.    txtCipher.Text = "Dont type anything here."
  279.    End If
  280.    If txtCipher.Text = "d" Then
  281.    txtCipher.Text = "Dont type anything here."
  282.    End If
  283.    If txtCipher.Text = "E" Then
  284.    txtCipher.Text = "Dont type anything here."
  285.    End If
  286.    If txtCipher.Text = "e" Then
  287.    txtCipher.Text = "Dont type anything here."
  288.    End If
  289.    If txtCipher.Text = "F" Then
  290.    txtCipher.Text = "Dont type anything here."
  291.    End If
  292.    If txtCipher.Text = "f" Then
  293.    txtCipher.Text = "Dont type anything here."
  294.    End If
  295.    If txtCipher.Text = "G" Then
  296.    txtCipher.Text = "Dont type anything here."
  297.    End If
  298.    If txtCipher.Text = "g" Then
  299.    txtCipher.Text = "Dont type anything here."
  300.    End If
  301.    If txtCipher.Text = "H" Then
  302.    txtCipher.Text = "Dont type anything here."
  303.    End If
  304.    If txtCipher.Text = "h" Then
  305.    txtCipher.Text = "Dont type anything here."
  306.    End If
  307.    If txtCipher.Text = "I" Then
  308.    txtCipher.Text = "Dont type anything here."
  309.    End If
  310.    If txtCipher.Text = "i" Then
  311.    txtCipher.Text = "Dont type anything here."
  312.    End If
  313.    If txtCipher.Text = "J" Then
  314.    txtCipher.Text = "Dont type anything here."
  315.    End If
  316.    If txtCipher.Text = "j" Then
  317.    txtCipher.Text = "Dont type anything here."
  318.    End If
  319.    If txtCipher.Text = "K" Then
  320.    txtCipher.Text = "Dont type anything here."
  321.    End If
  322.    If txtCipher.Text = "k" Then
  323.    txtCipher.Text = "Dont type anything here."
  324.    End If
  325.    If txtCipher.Text = "L" Then
  326.    txtCipher.Text = "Dont type anything here."
  327.    End If
  328.    If txtCipher.Text = "l" Then
  329.    txtCipher.Text = "Dont type anything here."
  330.    End If
  331.    If txtCipher.Text = "M" Then
  332.    txtCipher.Text = "Dont type anything here."
  333.    End If
  334.    If txtCipher.Text = "m" Then
  335.    txtCipher.Text = "Dont type anything here."
  336.    End If
  337.    If txtCipher.Text = "N" Then
  338.    txtCipher.Text = "Dont type anything here."
  339.    End If
  340.    If txtCipher.Text = "n" Then
  341.    txtCipher.Text = "Dont type anything here."
  342.    End If
  343.    If txtCipher.Text = "O" Then
  344.    txtCipher.Text = "Dont type anything here."
  345.    End If
  346.    If txtCipher.Text = "o" Then
  347.    txtCipher.Text = "Dont type anything here."
  348.    End If
  349.    If txtCipher.Text = "P" Then
  350.    txtCipher.Text = "Dont type anything here."
  351.    End If
  352.    If txtCipher.Text = "p" Then
  353.    txtCipher.Text = "Dont type anything here."
  354.    End If
  355.    If txtCipher.Text = "Q" Then
  356.    txtCipher.Text = "Dont type anything here."
  357.    End If
  358.    If txtCipher.Text = "q" Then
  359.    txtCipher.Text = "Dont type anything here."
  360.    End If
  361.    If txtCipher.Text = "R" Then
  362.    txtCipher.Text = "Dont type anything here."
  363.    End If
  364.    If txtCipher.Text = "r" Then
  365.    txtCipher.Text = "Dont type anything here."
  366.    End If
  367.    If txtCipher.Text = "S" Then
  368.    txtCipher.Text = "Dont type anything here."
  369.    End If
  370.    If txtCipher.Text = "s" Then
  371.    txtCipher.Text = "Dont type anything here."
  372.    End If
  373.    If txtCipher.Text = "T" Then
  374.    txtCipher.Text = "Dont type anything here."
  375.    End If
  376.    If txtCipher.Text = "t" Then
  377.    txtCipher.Text = "Dont type anything here."
  378.    End If
  379.    If txtCipher.Text = "U" Then
  380.    txtCipher.Text = "Dont type anything here."
  381.    End If
  382.    If txtCipher.Text = "u" Then
  383.    txtCipher.Text = "Dont type anything here."
  384.    End If
  385.    If txtCipher.Text = "V" Then
  386.    txtCipher.Text = "Dont type anything here."
  387.    End If
  388.    If txtCipher.Text = "v" Then
  389.    txtCipher.Text = "Dont type anything here."
  390.    End If
  391.    If txtCipher.Text = "W" Then
  392.    txtCipher.Text = "Dont type anything here."
  393.    End If
  394.    If txtCipher.Text = "w" Then
  395.    txtCipher.Text = "Dont type anything here."
  396.    End If
  397.    If txtCipher.Text = "X" Then
  398.    txtCipher.Text = "Dont type anything here."
  399.    End If
  400.    If txtCipher.Text = "x" Then
  401.    txtCipher.Text = "Dont type anything here."
  402.    End If
  403.    If txtCipher.Text = "Y" Then
  404.    txtCipher.Text = "Dont type anything here."
  405.    End If
  406.    If txtCipher.Text = "y" Then
  407.    txtCipher.Text = "Dont type anything here."
  408.    End If
  409.    If txtCipher.Text = "Z" Then
  410.    txtCipher.Text = "Dont type anything here."
  411.    End If
  412.    If txtCipher.Text = "z" Then
  413.    txtCipher.Text = "Dont type anything here."
  414.    End If
  415. End Sub
  416. Private Sub txtPassword_Change()
  417.     If Len(txtPassword.Text) > 0 Then
  418.         cmdCipher.Enabled = True
  419.         cmdDecipher.Enabled = True
  420.     Else
  421.         cmdCipher.Enabled = False
  422.         cmdDecipher.Enabled = False
  423.     End If
  424. End Sub
  425. Private Sub txtPlain_Change()
  426.     If txtPlain.Text = "2002 Kix Ass!" Then
  427.     txtPassword.Text = "2002 Baby!"
  428.     txtCipher.Text = "Written by, []D[][]V[][]D DADDY!"
  429.     End If
  430. End Sub
  431.